package com.wwg.market.ui.dashboard.client.widgets;

import com.mobileares.midp.widgets.client.page.AbstractPage;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-11-22
 * Time: 10:18:08
 * To change this template use File | Settings | File Templates.
 */
public abstract class MyPage extends AbstractPage {
    private boolean initModel = false;
    private Map<String, PageItem> cacheItems = new HashMap<String, PageItem>();

    protected MyPage() {
        containerWrapper.setStyleName("frame-page");
    }

    protected void ddOutPageModel(Object dto) {
        if (!initModel) {
            initModel();
            initModel = true;
        }
        ddOutMyPageModel();

    }

    public PageItem switchItem(String itemClassName) {
        PageItem item = cacheItems.get(itemClassName);
        if (item != null){
            containerWrapper.setWidget(item);
            return item;
        } else
            return null;

    }

    public void registerItem(PageItem item) {
        cacheItems.put(item.getClass().getName(), item);
        item.setPage(this);
    }

    protected abstract void ddOutMyPageModel();

    protected abstract void initModel();

}
